package cn.kgc.vue.controller;

import cn.kgc.vue.common.ResponseResult;
import cn.kgc.vue.common.ResponseStatus;
import cn.kgc.vue.entity.Dept;
import cn.kgc.vue.form.DeptLsitForm;
import cn.kgc.vue.service.DeptService;
import cn.kgc.vue.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 *@title DeptController
 *@author 韩旭
 *@version 1.0.0
 *@create 2023/8/13 21:17
 **/
@RestController
@RequestMapping("dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping("list")
    public ResponseResult list(){
        LambdaQueryWrapper<Dept> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(Dept::getId,Dept::getDeptName);
        List<Dept> list = deptService.list(wrapper);
        ResponseResult responseResult = new ResponseResult();
        responseResult.success(ResponseStatus.SUCCESS,list);
        return responseResult;
    }

    //模糊查询部门信息
    @GetMapping("getlists")
    public ResponseResult getlists(DeptLsitForm deptLsitForm){
        return deptService.getlists(deptLsitForm);
    }

    //修改和添加部门
    @PostMapping("addOrupdate")
    public ResponseResult addorupdate(@RequestBody Dept dept){
       return deptService.addorupdate(dept);
    }

    //删除部门
    @DeleteMapping("delete/{id}")
    public ResponseResult delete(@PathVariable("id") String id){
        return deptService.delete(id);
    }
}
